import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SalNotesXiangQing extends StatefulWidget {
  @override
  _SalNotesXiangQingState createState() => new _SalNotesXiangQingState();
}

class _SalNotesXiangQingState extends State<SalNotesXiangQing> {
  TextEditingController billNoController = new TextEditingController();
  TextEditingController billDateController = new TextEditingController();
  TextEditingController isRubricController = new TextEditingController();
  TextEditingController customerIdNameController = new TextEditingController();
  TextEditingController invoiceTypeController = new TextEditingController();
  TextEditingController qtyController = new TextEditingController();
  TextEditingController outQtyController = new TextEditingController();
  TextEditingController settleQtyController = new TextEditingController();
  var arguments;

  List<TableRow> tableRow = [];
  //物料明细
  List InfoList = [];
//页面加载完成时
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    //接受上个页面参数
    arguments = Get.arguments['Data'];
    InfoList = arguments['InfoList'];
    billNoController = new TextEditingController(text: arguments['billNo'].toString());
     billDateController = new TextEditingController(text:arguments['billDate'].toString());
     if(arguments['isRubric']==1){
       isRubricController = new TextEditingController(text:"Return".tr);
     }else{
       if(arguments['isRubric']==0){
         isRubricController = new TextEditingController(text:"normal".tr);
       }
     }

     customerIdNameController = new TextEditingController(text:arguments[' customerIdName'].toString());
     invoiceTypeController = new TextEditingController(text:arguments['invoiceType'].toString());
     qtyController = new TextEditingController(text:arguments['qty'].toInt().toString());
     outQtyController = new TextEditingController(text:arguments['outQty'].toInt().toString());
     settleQtyController = new TextEditingController(text:arguments['settleQty'].toString());
     tableRow.add(TableRow(
         children: [
           TableCell(child: Container(child: Text('material'.tr),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5),)),
           TableCell(child: Container(child: Text('Unitofmeasure'.tr),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
           TableCell(child: Container(child: Text('Specificationsandmodels'.tr),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
           TableCell(child: Container(child: Text('Scheduleoutboundshipments'.tr),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
           TableCell(child: Container(child: Text('Shippedout'.tr),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
         ]
     ));
    InfoList.forEach((item) {
      tableRow.add(TableRow(
          children: [
            TableCell(child: Container(child: Text(item['materialIdName']),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
            TableCell(child: Container(child: Text(item['unitIdName']),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
            TableCell(child: Container(child: Text(item['specificationAndModel']),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
            TableCell(child: Container(child: Text(item['qty'].toInt().toString()),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
            TableCell(child: Container(child: Text(item['shipmentNumber'].toInt().toString()),alignment: Alignment.center,padding: EdgeInsetsDirectional.all(5))),
          ]
      ));
    });


  }

  ///页面卸载
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  ///当 State 被暂时从视图树中移除时，会调用这个方法，同时页面切换时，也会调用。
  @override
  void deactivate() {
    // TODO: implement dispose
    super.deactivate();
  }

  ///在 initState() 之后调用，当 State 对象的依赖关系发生变化时，该方法被调用，初始化时也会调用。
  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
  }

  // TODO: add state variables and methods
  @override
  Widget build(BuildContext context) {
    // TODO: add widget build method
    return Scaffold(
      backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: Colors.white,
          title: Text("Salesrecorddetails".tr, style: TextStyle(fontSize: 15, color: Colors.black),),
          centerTitle: true,
          elevation: 0,
          iconTheme: IconThemeData(
              color: Colors.black
          ),
        ),
        body: SingleChildScrollView(
          child: Container(
            padding: EdgeInsets.all(15),
            child: Column(
              children: [
                //单据编号
                Container(
                  child: TextField(
                    enabled: false,
                    controller: billNoController,
                    decoration: InputDecoration(
                        hintText: "Documentnumber".tr,
                      labelText: "Documentnumber".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                //单据日期
                Container(
                  child: TextField(
                    enabled: false,
                    controller: billDateController,
                    decoration: InputDecoration(
                        hintText: "Documentdate".tr,
                      labelText: "Documentdate".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                //是否退货
                Container(
                  child: TextField(
                    enabled: false,
                    controller: isRubricController,
                    decoration: InputDecoration(
                        hintText: "Whethertoreturnthegoods".tr,
                      labelText: "Whethertoreturnthegoods".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                //客户
                Container(
                  child: TextField(
                    enabled: false,
                    controller: customerIdNameController,
                    decoration: InputDecoration(
                        hintText: "client".tr,
                      labelText: "client".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                //开票方式
                Container(
                  child: TextField(
                    enabled: false,
                    controller: invoiceTypeController,
                    decoration: InputDecoration(
                        hintText: "Invoicingmethod".tr,
                      labelText: "Invoicingmethod".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                //计划出库数
                Container(
                  child: TextField(
                    enabled: false,
                    controller: qtyController,
                    decoration: InputDecoration(
                        hintText: "Thenumberofplannedshipments".tr,
                      labelText: "Thenumberofplannedshipments".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                //已出库数
                Container(
                  child: TextField(
                    enabled: false,
                    controller: outQtyController,
                    decoration: InputDecoration(
                        hintText: "Thenumberofshipmentsthathavebeenshipped".tr,
                      labelText: "Thenumberofshipmentsthathavebeenshipped".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                //退货数
                Container(
                  child: TextField(
                    enabled: false,
                    controller: settleQtyController,
                    decoration: InputDecoration(
                        hintText: "Numberofreturns".tr,
                      labelText: "Numberofreturns".tr,
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.black12),
                      ),
                    ),
                  ),
                ),
                Container(
                  height: 15,
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  child: Text("Salesdetails".tr,style: TextStyle(fontSize: 17,fontWeight: FontWeight.w600),),
                ),
                Container(
                  height: 15,
                ),
                Container(
                  child: Table(
                    border: TableBorder(
                      horizontalInside: BorderSide(color: Colors.black12),
                      verticalInside: BorderSide(color: Colors.black12),
                      top: BorderSide(color: Colors.black12),
                      left: BorderSide(color: Colors.black12),
                      right: BorderSide(color: Colors.black12),
                      bottom: BorderSide(color: Colors.black12),
                    ),
                    children: tableRow,
                  ),
                )

              ],
            ),
          ),
        )
    );
  }
}
